package com.warehouseconsumer.controller;

import com.warehouseconsumer.service.StorehouseConsumerService;
import entity.ResponseMessage;
import entity.Storehouse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.UUID;

@Controller
@CrossOrigin
@RequestMapping("/storehouse")
public class StorehouseConsumerController {
    private Logger logger=Logger.getLogger(this.getClass());

    @Resource
    private StorehouseConsumerService storehouseConsumerService;
    /**
     * 根据条件分页查询仓库信息，条件为type 页可以无条件
     * @param storehouse
     * @param pageNo
     * @return
     */
    @RequestMapping(value = "/findAllStorehouse")
    @ResponseBody
    public ResponseMessage AllStorehouse(@RequestBody(required=false) Storehouse storehouse, @RequestParam("pageNo") int pageNo){
        logger.info("StorehouseConsumerController storehouse findAllStorehouse storehouse:"+storehouse+",pageNo:"+pageNo);
        int pageSize=2;//设置页容量
        ResponseMessage msg=new ResponseMessage();
        msg=storehouseConsumerService.findAllStorehouse(storehouse,pageNo,pageSize);
        return msg;
    }

    /**
     * 根据id查询该仓库信息
     * @param id
     * @return
     */
    @RequestMapping("/getidStorehouse")
    @ResponseBody
    public ResponseMessage getidStorehouse(@RequestParam("id") String id){
        logger.info("StorehouseConsumerController storehouse getidStorehouse id:"+id);
        ResponseMessage msg=new ResponseMessage();
        msg=storehouseConsumerService.getidStorehouse(id);
        return msg;
    }

    /**
     * 根据id修改仓库信息
     * @param storehouse
     * @return
     */
    @RequestMapping("/xgStorehouse")
    @ResponseBody
    public ResponseMessage xgStorehouse(@RequestBody Storehouse storehouse){
        logger.info("StorehouseConsumerController storehouse xgStorehouse storehouse:"+storehouse);
        ResponseMessage msg=new ResponseMessage();
        msg=storehouseConsumerService.xgStorehouse(storehouse);
        return msg;
    }
    /**
     * 查询总仓库
     * @return
     */
    @RequestMapping("/getQueryStronger")
    @ResponseBody
    public ResponseMessage getQueryStronger(){
        logger.info("StorehouseConsumerController storehouse getQueryStronger is start...");
        ResponseMessage msg=new ResponseMessage();
        msg=storehouseConsumerService.getQueryStronger();
        return msg;
    }

    /**
     * 增加仓库
     * @param storehouse
     * @return
     */
    @RequestMapping("/insertStronger")
    @ResponseBody
    public ResponseMessage insertStronger(@RequestBody Storehouse storehouse){
        logger.info("StorehouseConsumerController storehouse insertStronger storehouse:"+storehouse);
        storehouse.setId(UUID.randomUUID().toString());
        ResponseMessage msg=new ResponseMessage();
        msg=storehouseConsumerService.insertStronger(storehouse);
        return msg;
    }
}
